package com.ibiz.znjd.plugin;

import android.content.Intent;

import com.getcapacitor.JSObject;
import com.getcapacitor.NativePlugin;
import com.getcapacitor.Plugin;
import com.getcapacitor.PluginCall;
import com.getcapacitor.PluginMethod;
import com.ibiz.znjd.MainActivity;
import com.ibiz.znjd.MainApplication;
import com.ibiz.znjd.baidu.face.ExampleApplication;
import com.ibiz.znjd.baidu.face.HomeActivity;
import com.ibiz.znjd.znjd.FacePluginListener;

@NativePlugin()
public class FacePlugin extends Plugin {
    /**
     * 应用对象
     */
    private MainApplication app;

    @Override
    public void load(){
        // 初始化app
        app= ((MainApplication)(((MainActivity)getContext()).getApplication()));
    }

    /**
     * 设置全局环境变量
     * @param call
     */
    @PluginMethod()
    public void openFace(PluginCall call) {
        ExampleApplication.facePluginListener = new FacePluginListener() {
            @Override
            public void onCallback(JSObject result) {
                call.resolve(result);
                ExampleApplication.facePluginListener = null;
            }
        };
        // 启动活体检测
        Intent faceHome = new Intent(getContext(), HomeActivity.class);
        getContext().startActivity(faceHome);

    }
}
